/**
 * Author: Brent Myers
 * Time-stamp: <2008-07-23 17:13:43 bam>
 * 
 * Hashtable Tests
 * 
 */

#include <boost/test/unit_test.hpp>

#include "src/LinearProbe.h"
#include "src/SimpleHash.h"
#include "src/Hashtable.h"

#include <utility>

using std::make_pair;

using namespace genhash;

struct HTTestConfig1 
{
	enum { max_size = 10 };
	typedef int KeyType;
	typedef int DataType;
	typedef SimpleHash<HTTestConfig1> HashFn;
	typedef LinearProbe<HTTestConfig1> CollisionStrategy;
	typedef Hashtable<CollisionStrategy> RET;
};
typedef HTTestConfig1::RET HT1;

struct HTTestConfig2
{
	enum { max_size = 2 };
	typedef int KeyType;
	typedef int DataType;
	typedef SimpleHash<HTTestConfig2> HashFn;
	typedef LinearProbe<HTTestConfig2> CollisionStrategy;
	typedef Hashtable<CollisionStrategy> RET;
};
typedef HTTestConfig2::RET HT2;

BOOST_AUTO_TEST_CASE( ht1 )
{
	HT1 ht;
	ht.insert(make_pair(1, 2));
	HT1::iterator it(ht.find(1));
	BOOST_CHECK_EQUAL(it->first, 1);
	BOOST_CHECK_EQUAL(it->second, 2);
}

BOOST_AUTO_TEST_CASE( ht2 )
{
	HT1 ht;
	ht.insert(1, 2);
	HT1::iterator it(ht.find(1));
	BOOST_CHECK_EQUAL(it->first, 1);
	BOOST_CHECK_EQUAL(it->second, 2);
}


BOOST_AUTO_TEST_CASE( ht3 )
{
	HT1 ht;
	ht[1] = 2;
	BOOST_CHECK_EQUAL(ht[1], 2);
}


BOOST_AUTO_TEST_CASE( ht4 )
{
	HT1 ht;
	ht[1] = 2;
	ht[1] = 3;
	BOOST_CHECK_EQUAL(ht[1], 3);
}

